package com.hongdee.crm.kpi.controller;

import com.hongdee.base.entity.ResultEntity;
import com.hongdee.common.util.TokenUtil;
import com.hongdee.crm.kpi.service.IKPIService;
import com.hongdee.crm.statistics.task.service.ITCrmCarCountTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by My on 2017/3/1.
 */
@RestController
@RequestMapping("/crm/kpi")
public class KPIController {
    @Autowired
    private IKPIService ikpiService;
    @Autowired
    private ITCrmCarCountTaskService crmCarCountTaskService;

    /**
     * @param uid   登录用户id
     * @param token 登录用户 token
     * @param start 当前页面
     * @param limit 页面大小
     * @param name  活动名称
     * @return Map
     * @throws Exception
     * @desc 活动分页查询
     * @author 徐钦勇
     */
    @RequestMapping("/ActivePage")
    @ResponseBody
    public Map page(@RequestParam(name = "uid", defaultValue = "") String uid,
                    @RequestParam(name = "token", defaultValue = "") String token,
                    @RequestParam(name = "start", defaultValue = "0") String start,
                    @RequestParam(name = "limit", defaultValue = "50") String limit,
                    @RequestParam(name = "name", defaultValue = "") String name,
                    @RequestBody Map data) throws Exception {
        String oid = TokenUtil.getCompanyId(uid);
        Map map = ikpiService.ActivePage(start, limit, name, oid, data);
        map.put("success", true);
        map.put("msg", "分页查询成功！");
        return map;
    }

    @RequestMapping("/ActivePage/group")
    @ResponseBody
    public Map pageGroup(@RequestParam(name = "uid", defaultValue = "") String uid,
                    @RequestParam(name = "token", defaultValue = "") String token,
                    @RequestParam(name = "start", defaultValue = "0") String start,
                    @RequestParam(name = "limit", defaultValue = "50") String limit,
                    @RequestBody Map data) throws Exception {
        Map map = ikpiService.ActivePageGroup(uid,start, limit, data);
        map.put("success", true);
        map.put("msg", "分页查询成功！");
        return map;
    }
    /**
     * @param
     * @return Map
     * @throws Exception
     * @desc 活动分析报表
     * @author 徐钦勇
     */
    @RequestMapping("/activityTable")
    @ResponseBody
    public Map activityTable(@RequestParam(name = "uid", defaultValue = "") String uid,
                             @RequestParam(name = "token", defaultValue = "") String token,
                             @RequestParam(name = "activityId", defaultValue = "") String activityId) throws Exception {
        return this.ikpiService.activityTable(activityId);
    }

    /**
     * @param uid   登录用户id
     * @param token 登录用户 token
     * @param start 当前页面
     * @param limit 页面大小
     * @param id    活动id
     * @return Map
     * @throws Exception
     * @desc 优惠券详情
     * @author 徐钦勇
     */
    @RequestMapping("/CouponPage")
    @ResponseBody
    public Map CouponPage(@RequestParam(name = "uid", defaultValue = "") String uid,
                          @RequestParam(name = "token", defaultValue = "") String token,
                          @RequestParam(name = "start", defaultValue = "0") String start,
                          @RequestParam(name = "limit", defaultValue = "50") String limit,
                          @RequestParam(name = "id", defaultValue = "") String id,
                          @RequestParam(name = "type", defaultValue = "") String type,
                          @RequestParam(name = "timeType", defaultValue = "") String timeType,
                          @RequestBody Map data) throws Exception {
        Map map = ikpiService.CouponPage(uid, start, limit, id, type, timeType, data);
        map.put("success", true);
        map.put("msg", "分页查询成功！");
        return map;
    }

    /**
     * @param uid   登录用户id
     * @param token 登录用户 token
     * @param start 当前页面
     * @param limit 页面大小
     * @param mDate 时间
     * @return Map
     * @throws Exception
     * @desc SA过程管理
     * @author 徐钦勇
     */
    @RequestMapping("/SaProcess")
    @ResponseBody
    public Map SaProcess(@RequestParam(name = "uid", defaultValue = "") String uid,
                         @RequestParam(name = "token", defaultValue = "") String token,
                         @RequestParam(name = "start", defaultValue = "0") String start,
                         @RequestParam(name = "limit", defaultValue = "50") String limit,
                         @RequestParam(name = "mDate", defaultValue = "") String mDate,
                         @RequestParam(name = "companyId", defaultValue = "") String companyId,
                         @RequestParam(name = "area", defaultValue = "") String area,
                         @RequestParam(name = "brand", defaultValue = "") String brand) throws Exception {
        Map map = ikpiService.SaProcess(uid, start, limit, mDate,area,brand,companyId);
        map.put("success", true);
        map.put("msg", "分页查询成功！");
        return map;
    }

    /**
     * 任务穿透明细
     * @param uid
     * @param token
     * @param start
     * @param limit
     * @param mDate
     * @param type
     * @param pCode
     * @param status
     * @param saId
     * @param code
     * @return
     * @throws Exception
     */
    @RequestMapping("/SaProcess/detail")
    @ResponseBody
    public Map SaProcessDetail(@RequestParam(name = "uid", defaultValue = "") String uid,
                         @RequestParam(name = "token", defaultValue = "") String token,
                         @RequestParam(name = "start", defaultValue = "0") String start,
                         @RequestParam(name = "limit", defaultValue = "50") String limit,
                         @RequestParam(name = "mDate", defaultValue = "") String mDate,
                         @RequestParam(name = "type", defaultValue = "") String type,
                         @RequestParam(name = "pCode", defaultValue = "") String pCode,
                         @RequestParam(name = "status", defaultValue = "") String status,
                         @RequestParam(name = "saId", defaultValue = "") String saId,
                         @RequestParam(name = "code", defaultValue = "") String code,
                         @RequestParam(name = "companyId", defaultValue = "") String companyId) throws Exception {
        Map map = ikpiService.SaProcessDetail(uid,saId,start,limit,status,pCode,code,type,mDate,companyId);
        map.put("success", true);
        map.put("msg", "数据查询成功！");
        return map;
    }

    /**
     * 维系记录穿透明细
     * @param uid
     * @param token
     * @param start
     * @param limit
     * @param mDate
     * @param type
     * @param status
     * @return
     */
    @RequestMapping("/SaProcess/Contact/detail")
    @ResponseBody
    public Map SaProcessContactDetail(@RequestParam(name = "uid", defaultValue = "") String uid,
                                      @RequestParam(name = "token", defaultValue = "") String token,
                                      @RequestParam(name = "start", defaultValue = "0") String start,
                                      @RequestParam(name = "limit", defaultValue = "50") String limit,
                                      @RequestParam(name = "mDate", defaultValue = "") String mDate,
                                      @RequestParam(name = "type", defaultValue = "") String type,
                                      @RequestParam(name = "saId", defaultValue = "") String saId,
                                      @RequestParam(name = "status", defaultValue = "") String status,
                                      @RequestParam(name = "companyId", defaultValue = "") String companyId) throws Exception {
        Map map = ikpiService.SaProcessContactDetail(uid,mDate,type,status,saId,start,limit,companyId);
        map.put("success",true);
        map.put("msg","查询成功");
        return map;
    }

    /**
     * @param uid   登录用户id
     * @param token 登录用户 token
     * @param start 当前页面
     * @param limit 页面大小
     * @return Map
     * @throws Exception
     * @desc 车辆回厂率
     * @author 徐钦勇
     */
    @RequestMapping("/CarBackRate")
    @ResponseBody
    public Map CarBackRate(@RequestParam(name = "uid", defaultValue = "") String uid,
                           @RequestParam(name = "token", defaultValue = "") String token,
                           @RequestParam(name = "start", defaultValue = "0") String start,
                           @RequestParam(name = "limit", defaultValue = "50") String limit,
                           @RequestParam(name = "mDate", defaultValue = "") String mDate) throws Exception {
        Map map = this.ikpiService.CarBackRate(uid, start, limit, mDate);
        map.put("success", true);
        map.put("msg", "分页查询成功！");
        return map;
    }

    /** SA-工单匹配率-查询
     * @param uid   登录用户id
     * @param token 登录用户 token
     * @param start 当前页面
     * @param limit 页面大小
     * @return Map
     * @throws Exception
     * @desc SA工单匹配率workOrderMatchRate
     * @author 徐钦勇
     */
    @RequestMapping("/WorkOrderMatchRate")
    @ResponseBody
    public Map WorkOrderMatchRate(@RequestParam(name = "uid", defaultValue = "") String uid,
                                  @RequestParam(name = "token", defaultValue = "") String token,
                                  @RequestParam(name = "start", defaultValue = "0") String start,
                                  @RequestParam(name = "limit", defaultValue = "50") String limit,
                                  @RequestParam(name = "mDate", defaultValue = "") String mDate,
                                  @RequestParam(name = "mDate2", defaultValue = "") String mDate2,
                                  @RequestParam(name = "companyId", defaultValue = "") String companyId,
                                  @RequestParam(name = "area", defaultValue = "") String area,
                                  @RequestParam(name = "brand", defaultValue = "") String brand) throws Exception {
        List<Map<String, Object>> res = this.ikpiService.WorkOrderMatchRate(uid, start, limit, mDate,mDate2,companyId,area,brand);
        Map map = new HashMap();
        map.put("dataList", res);
        map.put("success", true);
        map.put("msg", "分页查询成功！");
        return map;
    }

    /**
     * @param uid   登录用户id
     * @param token 登录用户 token
     * @param start 当前页面
     * @param limit 页面大小
     * @return Map
     * @throws Exception
     * @desc 保养回厂率
     * @author 徐钦勇
     */
    @RequestMapping("/byBackRate")
    @ResponseBody
    public Map byBackRate(@RequestParam(name = "uid", defaultValue = "") String uid,
                          @RequestParam(name = "token", defaultValue = "") String token,
                          @RequestParam(name = "start", defaultValue = "0") String start,
                          @RequestParam(name = "limit", defaultValue = "50") String limit,
                          @RequestParam(name = "mDate", defaultValue = "") String mDate,
                          @RequestParam(name = "companyId", defaultValue = "") String companyId,
                          @RequestParam(name = "area", defaultValue = "") String area,
                          @RequestParam(name = "brand", defaultValue = "") String brand) throws Exception {
        Map map = new HashMap();
        map.put("dataList", this.ikpiService.byBackRate(uid, start, limit, mDate,companyId,area,brand));
        map.put("success", true);
        map.put("msg", "分页查询成功！");
        return map;
    }

    /**
     * 保养回厂数据穿透数据明细
     *
     * @param uid
     * @param token
     * @param start
     * @param limit
     * @param mDate
     * @param typeCode
     * @param isBack
     * @param saId
     * @return
     * @throws Exception
     */
    @RequestMapping("/byBackRate/detail")
    @ResponseBody
    public Map byBackRateDetail(@RequestParam(name = "uid", defaultValue = "") String uid,
                                @RequestParam(name = "token", defaultValue = "") String token,
                                @RequestParam(name = "start", defaultValue = "0") String start,
                                @RequestParam(name = "limit", defaultValue = "50") String limit,
                                @RequestParam(name = "mDate", defaultValue = "") String mDate,
                                @RequestParam(name = "typeCode", defaultValue = "") String typeCode,
                                @RequestParam(name = "isBack", defaultValue = "") String isBack,
                                @RequestParam(name = "saId", defaultValue = "") String saId,
                                @RequestParam(name = "companyId", defaultValue = "") String companyId) throws Exception {
        Map map = this.ikpiService.taskBackRateDetail(uid, start, limit, mDate, "by", typeCode, isBack, saId,companyId);
        map.put("success", true);
        map.put("msg", "分页查询成功！");
        return map;
    }


    /**
     * @param uid   登录用户id
     * @param token 登录用户 token
     * @return Map
     * @throws Exception
     * @desc 流失客服回访月报
     * @author 徐钦勇
     */
    @RequestMapping("/lsVisit")
    @ResponseBody
    public Map lsVisit(@RequestParam(name = "uid", defaultValue = "") String uid,
                       @RequestParam(name = "token", defaultValue = "") String token,
                       @RequestParam(name = "mDate", defaultValue = "") String mDate,
                       @RequestParam(name = "companyId", defaultValue = "") String companyId,
                       @RequestParam(name = "area", defaultValue = "") String area,
                       @RequestParam(name = "brand", defaultValue = "") String brand) throws Exception {
        Map map = new HashMap();
        List<Map> list = this.ikpiService.lsVisit(mDate, uid,companyId,area,brand);
        map.put("dataList", list);
        map.put("success", true);
        map.put("msg", "查询成功！");
        return map;
    }

    /**
     * @param uid   登录用户id
     * @param token 登录用户 token
     * @return Map
     * @throws Exception
     * @desc 新导入工单车辆数提醒
     * @author 徐钦勇
     */
    @RequestMapping("/newCarOrder")
    @ResponseBody
    public Map newCarOrder(@RequestParam(name = "uid", defaultValue = "") String uid,
                           @RequestParam(name = "token", defaultValue = "") String token,
                           @RequestParam(name = "mDate", defaultValue = "") String mDate) throws Exception {
        Map map = new HashMap();
        List<Map<String, Object>> list = this.ikpiService.newCarOrder(mDate, uid);
        map.put("dataList", list);
        map.put("success", true);
        map.put("msg", "查询成功！");
        return map;
    }

    /**
     * @param uid   登录用户id
     * @param token 登录用户 token
     * @param start 当前页面
     * @param limit 页面大小
     * @return Map
     * @throws Exception
     * @desc 流失客服回访明细
     * @author 徐钦勇
     */
    @RequestMapping("/lsVisitDetail")
    @ResponseBody
    public Map lsVisitDetail(@RequestParam(name = "uid", defaultValue = "") String uid,
                             @RequestParam(name = "token", defaultValue = "") String token,
                             @RequestParam(name = "start", defaultValue = "0") String start,
                             @RequestParam(name = "limit", defaultValue = "50") String limit,
                             @RequestParam(name = "mDate", defaultValue = "") String mDate,
                             @RequestParam(name = "companyId", defaultValue = "") String companyId,
                             @RequestParam(name = "area", defaultValue = "") String area,
                             @RequestParam(name = "brand", defaultValue = "") String brand) throws Exception {
        Map map = this.ikpiService.lsVisitDetail(uid, start, limit, mDate,companyId,area,brand);
        map.put("success", true);
        map.put("msg", "分页查询成功！");
        return map;
    }

    /**
     * @param uid   登录用户id
     * @param token 登录用户 token
     * @param start 当前页面
     * @param limit 页面大小
     * @return Map
     * @throws Exception
     * @desc 流失回厂数
     * @author 徐钦勇
     */
    @RequestMapping("/carLostBack")
    @ResponseBody
    public Map carLostBack(@RequestParam(name = "uid", defaultValue = "") String uid,
                           @RequestParam(name = "token", defaultValue = "") String token,
                           @RequestParam(name = "start", defaultValue = "0") String start,
                           @RequestParam(name = "limit", defaultValue = "50") String limit,
                           @RequestParam(name = "mDate", defaultValue = "") String mDate,
                           @RequestParam(name = "companyId", defaultValue = "") String companyId,
                           @RequestParam(name = "area", defaultValue = "") String area,
                           @RequestParam(name = "brand", defaultValue = "") String brand) throws Exception {
        Map map = this.ikpiService.carLostBack(uid, start, limit, mDate,companyId,area,brand);
        map.put("success", true);
        map.put("msg", "分页查询成功！");
        return map;
    }

    /**
     * 流失回厂数据穿透数据明细
     *
     * @param uid
     * @param token
     * @param start
     * @param limit
     * @param mDate
     * @param typeCode
     * @param isBack
     * @param saId
     * @return
     * @throws Exception
     */
    @RequestMapping("/carLostBack/detail")
    @ResponseBody
    public Map carLostBackDetail(@RequestParam(name = "uid", defaultValue = "") String uid,
                                 @RequestParam(name = "token", defaultValue = "") String token,
                                 @RequestParam(name = "start", defaultValue = "0") String start,
                                 @RequestParam(name = "limit", defaultValue = "50") String limit,
                                 @RequestParam(name = "mDate", defaultValue = "") String mDate,
                                 @RequestParam(name = "typeCode", defaultValue = "") String typeCode,
                                 @RequestParam(name = "isBack", defaultValue = "") String isBack,
                                 @RequestParam(name = "saId", defaultValue = "") String saId,
                                 @RequestParam(name = "companyId", defaultValue = "") String companyId) throws Exception {
        Map map = this.ikpiService.taskBackRateDetail(uid, start, limit, mDate, "ls", typeCode, isBack, saId,companyId);
        map.put("success", true);
        map.put("msg", "分页查询成功！");
        return map;
    }

    /**
     * @param uid   登录用户id
     * @param token 登录用户 token
     * @param start 当前页面
     * @param limit 页面大小
     * @return Map
     * @throws Exception
     * @desc 月度回厂任务
     * @author 徐钦勇
     */
    @RequestMapping("/MonthBackTask")
    @ResponseBody
    public Map MonthBackTask(@RequestParam(name = "uid", defaultValue = "") String uid,
                             @RequestParam(name = "token", defaultValue = "") String token,
                             @RequestParam(name = "start", defaultValue = "0") String start,
                             @RequestParam(name = "limit", defaultValue = "50") String limit,
                             @RequestParam(name = "mDate", defaultValue = "") String mDate,
                             @RequestParam(name = "companyId", defaultValue = "") String companyId,
                             @RequestParam(name = "area", defaultValue = "") String area,
                             @RequestParam(name = "brand", defaultValue = "") String brand) throws Exception {
        Map map = this.ikpiService.MonthBackTask(uid, start, limit, mDate,companyId,area,brand);
        map.put("success", true);
        map.put("msg", "分页查询成功！");
        return map;
    }

    /**
     * 月度目标任务穿透明细
     *
     * @param uid
     * @param token
     * @param start
     * @param limit
     * @param mDate
     * @param typeCode
     * @param saId
     * @param status
     * @return
     * @throws Exception
     */
    @RequestMapping("/MonthBackTask/detail")
    @ResponseBody
    public Map MonthBackTaskEetail(@RequestParam(name = "uid", defaultValue = "") String uid,
                                   @RequestParam(name = "token", defaultValue = "") String token,
                                   @RequestParam(name = "start", defaultValue = "0") String start,
                                   @RequestParam(name = "limit", defaultValue = "50") String limit,
                                   @RequestParam(name = "mDate", defaultValue = "") String mDate,
                                   @RequestParam(name = "typeCode", defaultValue = "") String typeCode,
                                   @RequestParam(name = "saId", defaultValue = "") String saId,
                                   @RequestParam(name = "status", defaultValue = "") String status,
                                   @RequestParam(name = "companyId", defaultValue = "") String companyId) throws Exception {
        Map map = this.ikpiService.taskBackRateDetail(uid, start, limit, mDate, "by", typeCode, "", saId, status,companyId);
        map.put("success", true);
        map.put("msg", "分页查询成功！");
        return map;
    }

    /**
     * @param uid   登录用户id
     * @param token 登录用户token
     * @param yDate 查询条件年份
     * @return Map
     * @throws Exception
     * @desc 事故车到店率
     * @author 侯念晨
     */
    @RequestMapping("/carback")
    public List CarBack(@RequestParam(name = "uid", defaultValue = "") String uid,
                        @RequestParam(name = "token", defaultValue = "") String token,
                        @RequestParam(name = "yDate", defaultValue = "") String yDate,
                        @RequestParam(name = "companyId", defaultValue = "") String companyId,
                        @RequestParam(name = "area", defaultValue = "") String area,
                        @RequestParam(name = "brand", defaultValue = "") String brand) throws Exception {
        List list = this.ikpiService.CarBack(uid, yDate,companyId,area,brand);
        return list;
    }

    /**
     * 事故车回场率
     *
     * @param uid
     * @param token
     * @param type
     * @param year
     * @param month
     * @param start
     * @param limit
     * @return
     * @throws Exception
     */
    @RequestMapping("/carback/detail")
    public Map CarBackDetail(@RequestParam(name = "uid", defaultValue = "") String uid,
                             @RequestParam(name = "token", defaultValue = "") String token,
                             @RequestParam(name = "type", defaultValue = "") String type,
                             @RequestParam(name = "year", defaultValue = "") String year,
                             @RequestParam(name = "companyId", defaultValue = "") String companyId,
                             @RequestParam(name = "month", defaultValue = "") String month,
                             @RequestParam(name = "start", defaultValue = "") String start,
                             @RequestParam(name = "limit", defaultValue = "") String limit) throws Exception {
        if("".equals(companyId)){
            throw new Exception("请选择公司信息!!");
        }
        Map map = this.crmCarCountTaskService.sgCarPree(companyId,month, year, uid, type, start, limit);
        map.put("success", true);
        map.put("msg", "查询成功!!");
        return map;
    }

    /**
     * @param uid   登录用户id
     * @param token 登录用户token
     * @param yDate 查询条件年份
     * @param sa    人员
     * @return Map
     * @throws Exception
     * @desc 出保车辆到店率
     * @author 侯念晨
     */
    @RequestMapping("/cbcarback")
    public List cbcarback(@RequestParam(name = "uid", defaultValue = "") String uid,
                          @RequestParam(name = "token", defaultValue = "") String token,
                          @RequestParam(name = "yDate", defaultValue = "") String yDate,
                          @RequestParam(name = "sa", defaultValue = "") String sa,
                          @RequestParam(name = "companyId", defaultValue = "") String companyId,
                          @RequestParam(name = "area", defaultValue = "") String area,
                          @RequestParam(name = "brand", defaultValue = "") String brand) throws Exception {
        /***
         * 非管理员仅能查看自己
         * **/
        if (!TokenUtil.isCompanyAdmin(uid)) {
            sa = uid;
        }
        List list = this.ikpiService.cbcarback(uid, yDate, sa,companyId,area,brand);
        return list;
    }


    /**
     * 车辆出保到店率明细
     *
     * @param uid
     * @param token
     * @param saId
     * @param type
     * @param year
     * @param month
     * @param start
     * @param limit
     * @return
     * @throws Exception
     */
    @RequestMapping("/cbcarback/detail")
    public Map cbcarbackDetail(@RequestParam(name = "uid", defaultValue = "") String uid,
                               @RequestParam(name = "token", defaultValue = "") String token,
                               @RequestParam(name = "saId", defaultValue = "") String saId,
                               @RequestParam(name = "type", defaultValue = "") String type,
                               @RequestParam(name = "year", defaultValue = "") String year,
                               @RequestParam(name = "month", defaultValue = "") String month,
                               @RequestParam(name = "companyId", defaultValue = "") String companyId,
                               @RequestParam(name = "start", defaultValue = "") String start,
                               @RequestParam(name = "limit", defaultValue = "") String limit) throws Exception {
        Map map = this.crmCarCountTaskService.zbCarPree(month, year, saId, uid, type, start, limit,companyId);
        map.put("success", true);
        map.put("msg", "查询成功!!");
        return map;
    }

    /**
     * @param uid   登录用户id
     * @param token 登录用户token
     * @param yDate 查询条件年份
     * @param sa    人员
     * @return Map
     * @throws Exception
     * @desc 客户定保到场率
     * @author 侯念晨
     */
    @RequestMapping("/dbcarback")
    public List dbcarback(@RequestParam(name = "uid", defaultValue = "") String uid,
                          @RequestParam(name = "token", defaultValue = "") String token,
                          @RequestParam(name = "yDate", defaultValue = "") String yDate,
                          @RequestParam(name = "sa", defaultValue = "") String sa,
                          @RequestParam(name = "companyId", defaultValue = "") String companyId,
                          @RequestParam(name = "area", defaultValue = "") String area,
                          @RequestParam(name = "brand", defaultValue = "") String brand) throws Exception {
        /***
         * 非管理员仅能查看自己
         * **/
        if (!TokenUtil.isCompanyAdmin(uid)) {
            sa = uid;
        }
        List list = this.ikpiService.dbcarback(uid, yDate, sa,companyId,area,brand);
        return list;
    }

    /**
     * 客户定保到场率明细
     *
     * @param uid
     * @param token
     * @param saId
     * @param type
     * @param year
     * @param month
     * @param start
     * @param limit
     * @return
     * @throws Exception
     */
    @RequestMapping("/dbcarback/detail")
    public Map dbCarBackDetail(@RequestParam(name = "uid", defaultValue = "") String uid,
                               @RequestParam(name = "token", defaultValue = "") String token,
                               @RequestParam(name = "saId", defaultValue = "") String saId,
                               @RequestParam(name = "type", defaultValue = "") String type,
                               @RequestParam(name = "year", defaultValue = "") String year,
                               @RequestParam(name = "month", defaultValue = "") String month,
                               @RequestParam(name = "start", defaultValue = "") String start,
                               @RequestParam(name = "limit", defaultValue = "") String limit,
                               @RequestParam(name = "companyId", defaultValue = "") String companyId) throws Exception {
        Map map = this.crmCarCountTaskService.dbCarPree(month, year, saId, uid, type, start, limit,companyId);
        map.put("success", true);
        map.put("msg", "查询成功!!");
        return map;
    }

    /**
     * 产值分析报表,取已时间段每日产值数据
     *
     * @param uid
     * @param token
     * @param data
     * @return
     * @throws Exception
     */
    @RequestMapping("/balaceAnalysis")
    public ResultEntity balaceAnalysis(@RequestParam(name = "uid", defaultValue = "") String uid,
                                       @RequestParam(name = "token", defaultValue = "") String token,
                                       @RequestBody Map data) throws Exception {
        List list = this.ikpiService.balaceAnalysis(uid, data);
        ResultEntity resultEntity = new ResultEntity();
        resultEntity.setDataList(list);
        resultEntity.setMsg("查询成功");
        resultEntity.setSuccess(true);
        return resultEntity;
    }


    /**
     * @Name:进厂辆次接口
     * @Date: 2017/8/21 15:56
     * @Author: Liu XiaoLong
     */
    @RequestMapping("/enterVehicleNum")
    public ResultEntity enterVehicleNum(@RequestParam(name = "uid", defaultValue = "") String uid,
                                       @RequestParam(name = "token", defaultValue = "") String token,
                                       @RequestBody Map data) throws Exception {
        List list = this.ikpiService.enterVehicleNum(uid, data);
        ResultEntity resultEntity = new ResultEntity();
        resultEntity.setDataList(list);
        resultEntity.setMsg("查询成功");
        resultEntity.setSuccess(true);
        return resultEntity;
    }

    /**
     * 新增基盘趋势
     *
     * @param uid
     * @param token
     * @param DateYearMonth
     * @return
     * @throws Exception
     */
    @RequestMapping("/newAddBaseData")
    public ResultEntity newAddBaseData(@RequestParam(name = "uid", defaultValue = "") String uid,
                                       @RequestParam(name = "token", defaultValue = "") String token,
                                       @RequestParam(name = "companyId", defaultValue = "") String companyId,
                                       @RequestParam(name = "area", defaultValue = "") String area,
                                       @RequestParam(name = "brand", defaultValue = "") String brand,
                                       @RequestParam(name = "DateYearMonth", defaultValue = "") String DateYearMonth) throws Exception {
        List list = this.ikpiService.newAddBaseData(uid, DateYearMonth,companyId,area,brand);
        ResultEntity resultEntity = new ResultEntity();
        resultEntity.setDataList(list);
        resultEntity.setMsg("查询成功");
        resultEntity.setSuccess(true);
        return resultEntity;
    }

    /**
     * 新增基盘趋势明细分页查询
     *
     * @param uid
     * @param token
     * @param start
     * @param limit
     * @param DateYearMonthDay
     * @return
     * @throws Exception
     */
    @RequestMapping("/newAddBaseDataDetail")
    @ResponseBody
    public Map page(@RequestParam(name = "uid", defaultValue = "") String uid,
                    @RequestParam(name = "token", defaultValue = "") String token,
                    @RequestParam(name = "start", defaultValue = "0") String start,
                    @RequestParam(name = "limit", defaultValue = "50") String limit,
                    @RequestParam(name = "companyId", defaultValue = "") String companyId,
                    @RequestParam(name = "DateYearMonthDay", defaultValue = "") String DateYearMonthDay) throws Exception {

        Map map = this.ikpiService.newAddBaseDataDetail(uid, DateYearMonthDay, start, limit,companyId);
        map.put("success", true);
        map.put("msg", "分页查询成功！");
        return map;
    }
    /**
     * @Name: 基盘车辆车型分布
     * @Author: Liu XiaoLong
     * @Date: 2017/8/30 15:24
     */
    @RequestMapping("/baseCarModel")
    @ResponseBody
    public Map baseCarModel(@RequestParam(name = "uid", defaultValue = "") String uid,
                            @RequestParam(name = "token", defaultValue = "") String token,
                            @RequestParam(name = "start", defaultValue = "0") String start,
                            @RequestParam(name = "limit", defaultValue = "50") String limit,
                            @RequestBody Map map) throws Exception {
        Map map1 = this.ikpiService.baseCarSerice(uid,map,start,limit);
        map1.put("success",true);
        map1.put("msg","查询成功！");
        return map1;
    }
    /**
     * @Name: 基盘车辆车型分布 【详情】
     * @Author: Liu XiaoLong
     * @Date: 2017/9/6 15:06
     * @Remark:
     */
    @RequestMapping("/baseCarSericeDetail")
    @ResponseBody
    public Map baseCarSericeDetail(@RequestParam(name = "uid", defaultValue = "") String uid,
                                        @RequestParam(name = "token", defaultValue = "") String token,
                                        @RequestParam(name = "start", defaultValue = "0") String start,
                                        @RequestParam(name = "limit", defaultValue = "50") String limit,
                                        @RequestParam(name = "companyId", defaultValue = "") String companyId,
                                        @RequestBody Map data) throws Exception {
        //String cid = TokenUtil.getCompanyId(uid);
        Map map = this.ikpiService.baseCarSericeDetail(uid,start,limit,companyId,data);
        map.put("success", true);
        map.put("msg", "查询成功！");
        return map;
    }
    /**
     * @Name: 基盘车辆车龄分布
     * @Author: Liu XiaoLong
     * @Date: 2017/8/30 15:25
     */
    @RequestMapping("/baseCarAge")
    @ResponseBody
    public Map baseCarAge(@RequestParam(name = "uid", defaultValue = "") String uid,
                            @RequestParam(name = "token", defaultValue = "") String token,
                            @RequestParam(name = "start", defaultValue = "0") String start,
                            @RequestParam(name = "limit", defaultValue = "50") String limit,
                            @RequestBody Map map) throws Exception {
        Map map1 = this.ikpiService.baseCarAge(uid,map,start,limit);
        map1.put("success",true);
        map1.put("msg","查询成功！");
        return map1;
    }
    /**
     * @Name: 基盘车辆贡献分布
     * @Author: Liu XiaoLong
     * @Date: 2017/8/31 15:27
     */
    @RequestMapping("/baseCarContribution")
    @ResponseBody
    public Map baseCarContribution(@RequestParam(name = "uid", defaultValue = "") String uid,
                          @RequestParam(name = "token", defaultValue = "") String token,
                          @RequestParam(name = "start", defaultValue = "0") String start,
                          @RequestParam(name = "limit", defaultValue = "50") String limit,
                          @RequestBody Map map) throws Exception {
        Map map1 = this.ikpiService.baseCarContribution(uid,map,start,limit);
        map1.put("success",true);
        map1.put("msg","查询成功！");
        return map1;
    }
    /**
     * @Name: 基盘车辆贡献 【详情】
     * @Author: Liu XiaoLong
     * @Date: 2017/9/6 17:02
     * @Remark:
     */
    @RequestMapping("/baseCarContributionDetail")
    @ResponseBody
    public Map baseCarContributionDetail(@RequestParam(name = "uid", defaultValue = "") String uid,
                                   @RequestParam(name = "token", defaultValue = "") String token,
                                   @RequestParam(name = "start", defaultValue = "0") String start,
                                   @RequestParam(name = "limit", defaultValue = "50") String limit,
                                   @RequestParam(name = "companyId", defaultValue = "") String companyId,
                                   @RequestBody Map data) throws Exception {
        //String cid = TokenUtil.getCompanyId(uid);
        Map map = this.ikpiService.baseCarContributionDetail(uid,start,limit,companyId,data);
        map.put("success", true);
        map.put("msg", "查询成功！");
        return map;
    }
    /**
     * @Name: 基盘消费频次
     * @Author: Liu XiaoLong
     * @Date: 2017/9/4 14:04
     */
    @RequestMapping("/baseCarConsumption")
    @ResponseBody
    public Map baseCarConsumption(@RequestParam(name = "uid", defaultValue = "") String uid,
                                   @RequestParam(name = "token", defaultValue = "") String token,
                                   @RequestParam(name = "start", defaultValue = "0") String start,
                                   @RequestParam(name = "limit", defaultValue = "50") String limit,
                                   @RequestBody Map map) throws Exception {
        Map map1 = this.ikpiService.baseCarConsumption(uid,map,start,limit);
        map1.put("success",true);
        map1.put("msg","查询成功！");
        return map1;
    }
    /**
     * @Name: 基盘消费频次 【详情】
     * @Author: Liu XiaoLong
     * @Date: 2017/9/5 11:17
     */
    @RequestMapping("/baseCarConsumptionDetail")
    @ResponseBody
    public Map baseCarConsumptionDetail(@RequestParam(name = "uid", defaultValue = "") String uid,
                           @RequestParam(name = "token", defaultValue = "") String token,
                           @RequestParam(name = "start", defaultValue = "0") String start,
                           @RequestParam(name = "limit", defaultValue = "50") String limit,
                           @RequestParam(name = "companyId", defaultValue = "") String companyId,
                           @RequestBody Map data) throws Exception {
        //String cid = TokenUtil.getCompanyId(uid);
        Map map = this.ikpiService.baseCarDetail(uid,start,limit,companyId,data);
        map.put("success", true);
        map.put("msg", "查询成功！");
        return map;
    }
    /**
     * @Name: 基盘车辆车龄分布 【详情】
     * @Author: Liu XiaoLong
     * @Date: 2017/9/5 19:35
     */
    @RequestMapping("/baseCarAgeDetail")
    @ResponseBody
    public Map baseCarAgeDetail(@RequestParam(name = "uid", defaultValue = "") String uid,
                           @RequestParam(name = "token", defaultValue = "") String token,
                           @RequestParam(name = "start", defaultValue = "0") String start,
                           @RequestParam(name = "limit", defaultValue = "50") String limit,
                           @RequestParam(name = "companyId", defaultValue = "") String companyId,
                           @RequestBody Map data) throws Exception {
        //String cid = TokenUtil.getCompanyId(uid);
        Map map = this.ikpiService.baseCarAgeDetail(uid,start,limit,companyId,data);
        map.put("success", true);
        map.put("msg", "查询成功！");
        return map;
    }


    /**
     * 流失基盘趋势
     *
     * @param uid
     * @param token
     * @param DateYearMonth
     * @return
     * @throws Exception
     */
    @RequestMapping("/lostBaseData")
    public ResultEntity lostBaseData(@RequestParam(name = "uid", defaultValue = "") String uid,
                                     @RequestParam(name = "token", defaultValue = "") String token,
                                     @RequestParam(name = "DateYearMonth", defaultValue = "") String DateYearMonth,
                                     @RequestParam(name = "companyId", defaultValue = "") String companyId,
                                     @RequestParam(name = "area", defaultValue = "") String area,
                                     @RequestParam(name = "brand", defaultValue = "") String brand) throws Exception {
        List list = this.ikpiService.lostBaseData(uid, DateYearMonth,companyId,area,brand);
        ResultEntity resultEntity = new ResultEntity();
        resultEntity.setDataList(list);
        resultEntity.setMsg("查询成功");
        resultEntity.setSuccess(true);
        return resultEntity;
    }
    /**
     * 流失基盘趋势明细分页查询
     *
     * @param uid
     * @param token
     * @param start
     * @param limit
     * @param DateYearMonthDay
     * @return
     * @throws Exception
     */
    @RequestMapping("/lostBaseDataDetail")
    @ResponseBody
    public Map lostBaseDataDetail(@RequestParam(name = "uid", defaultValue = "") String uid,
                    @RequestParam(name = "token", defaultValue = "") String token,
                    @RequestParam(name = "start", defaultValue = "0") String start,
                    @RequestParam(name = "limit", defaultValue = "50") String limit,
                    @RequestParam(name = "DateYearMonthDay", defaultValue = "") String DateYearMonthDay,
                    @RequestParam(name = "companyId", defaultValue = "") String companyId) throws Exception {

        Map map = this.ikpiService.lostBaseDataDetail(uid, DateYearMonthDay, start, limit,companyId);
        map.put("success", true);
        map.put("msg", "分页查询成功！");
        return map;
    }

    /**
     * @Name: 流失车辆表
     * @Author: Liu XiaoLong
     * @Date: 2017/9/10 22:52
     * @Remark:
     */
    @RequestMapping("/lostCarTable")
    @ResponseBody
    public Map lostCarTable(@RequestParam(name = "uid", defaultValue = "") String uid,
                            @RequestParam(name = "token", defaultValue = "") String token,
                            @RequestParam(name = "start", defaultValue = "0") String start,
                            @RequestParam(name = "limit", defaultValue = "50") String limit,
                            @RequestParam(name = "companyId", defaultValue = "") String companyId,
                            @RequestBody Map data) throws Exception {
        //String cid = TokenUtil.getCompanyId(uid);
        Map map = this.ikpiService.lostCarTable(uid,data,start,limit);
        map.put("success", true);
        map.put("msg", "查询成功！");
        return map;
    }
    /**
     * @Name: 流失车辆表详情
     * @Author: Liu XiaoLong
     * @Date: 2017/9/10 23:33
     * @Remark:
     */
    @RequestMapping("/lostCarTableDetail")
    @ResponseBody
    public Map lostCarTableDetail(@RequestParam(name = "uid", defaultValue = "") String uid,
                                  @RequestParam(name = "token", defaultValue = "") String token,
                                  @RequestParam(name = "start", defaultValue = "0") String start,
                                  @RequestParam(name = "limit", defaultValue = "50") String limit,
                                  @RequestParam(name = "companyId", defaultValue = "") String companyId,
                                  @RequestBody Map data) throws Exception {
        //String cid = TokenUtil.getCompanyId(uid);
        Map map = this.ikpiService.lostCarTableDetail(uid,data,start,limit);
        map.put("success", true);
        map.put("msg", "查询成功！");
        return map;
    }

    /**
     * 保险任务过程管理
     */
    @RequestMapping("/insuranceTsakQuery")
    @ResponseBody
    public Map insuranceTsakQuery(@RequestParam(name = "uid", defaultValue = "") String uid,
                                  @RequestParam(name = "token", defaultValue = "") String token,
                                  @RequestParam(name = "area", defaultValue = "") String area,
                                  @RequestParam(name = "brand", defaultValue = "") String brand,
                                  @RequestParam(name = "companyId", defaultValue = "") String companyId,
                                  @RequestParam(name = "month", defaultValue = "") String month,
                                  @RequestParam(name = "start", defaultValue = "0") String start,
                                  @RequestParam(name = "limit", defaultValue = "50") String limit) throws Exception{

        Map map = this.ikpiService.insuranceTsakQuery(uid,token,area,brand,companyId,month,start,limit);
        map.put("success","true");
        map.put("msg","查询成功");
        return map;
    }

    /**
     * @name：保险任务过程管理明细查询
     * @Author: 侯念晨
     * @Date：2017/11/22
     * @param uid
     * @param token
     * @param companyId
     * @param saId
     * @param type 保险任务类型
     * @param time
     * @return
     * @throws Exception
     */
    @RequestMapping("/insuranceTaskDetail")
    @ResponseBody
    public Map insuranceTaskDetail(@RequestParam(name = "uid", defaultValue = "") String uid,
                                   @RequestParam(name = "token", defaultValue = "") String token,
                                   @RequestParam(name = "companyId", defaultValue = "") String companyId,
                                   @RequestParam(name = "saId", defaultValue = "") String saId,
                                   @RequestParam(name = "type", defaultValue = "") String type,
                                   @RequestParam(name = "time", defaultValue = "") String time,
                                   @RequestParam(name = "start", defaultValue = "") String start,
                                   @RequestParam(name = "limit", defaultValue = "") String limit) throws Exception{
        Map map = this.ikpiService.insuranceTaskDetail(uid,token,companyId,saId,type,time,start,limit);
        map.put("success","true");
        map.put("msg","查询成功");
        return map;
    }
}
